package com.zprmb.udzt.adapter;

import java.text.DecimalFormat;
import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.Back_New_Uplan;
import com.zprmb.udzt.util.Regular;

public class Back_New_Adapter extends BaseAdapter {
	private List<Back_New_Uplan> list;
	private Context context;
	private DecimalFormat df = new DecimalFormat("###0.00");
    private String title;
	

	public Back_New_Adapter(List<Back_New_Uplan> list, Context context,
			String title) {
		super();
		this.list = list;
		this.context = context;
		this.title = title;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Help h=null;
		if(convertView==null){
			h=new Help();
			convertView=LayoutInflater.from(context).inflate(R.layout.back_money_item, null);
			h.rl_add_money=(RelativeLayout)convertView.findViewById(R.id.rl_add_money);
			h.tv_addmoney=(TextView)convertView.findViewById(R.id.tv_add_money);
			h.rl_add_money2=(RelativeLayout)convertView.findViewById(R.id.rl_add_money2);
			h.tv_date=(TextView)convertView.findViewById(R.id.back_date);
			h.tv_add_money_pl=(TextView)convertView.findViewById(R.id.tv_add_money_pl);
			h.tv_interest=(TextView)convertView.findViewById(R.id.back_interest);
			h.tv_principal=(TextView)convertView.findViewById(R.id.back_principal);
			h.tv_status=(TextView)convertView.findViewById(R.id.tv_status);
			h.tv_back_money=(TextView)convertView.findViewById(R.id.tv_back_money);
			h.w_xian=(ImageView)convertView.findViewById(R.id.w_xian);
			convertView.setTag(h);
		}else{
			h=(Help) convertView.getTag();
		}
		if(title.equals("理财中")){
			h.tv_back_money.setText("预计回款日期");
		}else{
			h.tv_back_money.setText("回款日期");
		}
		
		
	   if(list.get(position).getRaiseInterestAmount()!=null&&Double.parseDouble(list.get(position).getRaiseInterestAmount())>0){
		   h.rl_add_money.setVisibility(View.VISIBLE);
		   h.tv_addmoney.setText(list.get(position).getRaiseInterestAmount());
		   h.w_xian.setVisibility(View.VISIBLE);
		   
	   }else{
		   h.rl_add_money.setVisibility(View.GONE);
		   h.w_xian.setVisibility(View.GONE);
	   }
	   if(list.get(position).getAddInterestAmount()!=null&&Double.parseDouble(list.get(position).getAddInterestAmount())>0){
		   h.rl_add_money2.setVisibility(View.VISIBLE);
		   h.tv_add_money_pl.setText(list.get(position).getAddInterestAmount());
		   h.w_xian.setVisibility(View.VISIBLE);
	   }else{
		   h.rl_add_money2.setVisibility(View.GONE);
		   if(list.get(position).getRaiseInterestAmount()!=null&&Double.parseDouble(list.get(position).getRaiseInterestAmount())>0){
			   
		   }else{
			   h.w_xian.setVisibility(View.GONE);
			   
		   }
	   }
	   h.tv_date.setText(Regular.getMilliToDate(list.get(position).getRepayTime()));
	   h.tv_interest.setText(df.format(Double.parseDouble(list.get(position).getAmountInterest())));
	   h.tv_principal.setText(df.format(Double.parseDouble(list.get(position).getAmountPrincipal())));
	   h.tv_status.setText(list.get(position).getRepayStatusName());
	   if(list.get(position).getRepayStatusName().indexOf("待收")==0){
		   h.tv_status.setTextColor(Color.parseColor("#FF0000"));
	   }else{
		   h.tv_status.setTextColor(Color.parseColor("#999999"));
	   }
		return convertView;
	}
	class Help{
		private TextView tv_date,tv_principal,tv_interest,tv_addmoney,tv_status,tv_add_money_pl,tv_back_money;
		private ImageView w_xian;
		private RelativeLayout rl_add_money,rl_add_money2;
	}

}
